/**
 * @file
 * @auth jinguangguo
 * @date 2016/10/17
 */

import gulp from 'gulp';
import webpack from 'gulp-webpack';
import uglify from 'gulp-uglify';
import md5 from 'gulp-md5-plus';
import webpackConfig from '../../webpack.config.babel';
import util from '../util';

gulp.task('dep:dev', function () {
    return gulp.src('./grsc-base/dep/**/*')
        .pipe(gulp.dest('./dev/dep'))
});

gulp.task('js:dev', ['dep:dev'], function () {
    webpackConfig.devtool = 'source-map';
    try {
        return gulp
            .src('./src/js/*.js')
            .pipe(webpack(webpackConfig))
            .pipe(gulp.dest('./dev'));
    } catch(e) {
        console.log(e.message);
    }

});

gulp.task('js:server', ['dep:dev']);

gulp.task('dep-min', ['dep:dev'], function () {
    return gulp
        .src('./dev/dep/*.js')
        .pipe(uglify())
        .pipe(gulp.dest('./prod/dep'));
});

gulp.task('js:prod', ['js:dev'], function () {
    return gulp
        .src('./dev/**/*.js')
        .pipe(uglify())
        .pipe(md5(6, './prod/**/*.html'))
        .pipe(gulp.dest('./prod'));
});
